package com.bana.fvs.app.mvp.presenter;

import android.app.Activity;

import com.bana.fvs.app.module.detaile.entity.AreaControllerDetailBean;
import com.bana.fvs.app.module.detaile.entity.CommonEntity;
import com.bana.fvs.app.module.detaile.entity.FogAreaInfoBean;
import com.bana.fvs.app.module.detaile.entity.FoglightDetailInfo;
import com.bana.fvs.app.module.detaile.entity.UpdateWorkModeResultBean;
import com.bana.fvs.app.module.detaile.entity.VisibilityControllerDetailBean;
import com.bana.fvs.app.mvp.contract.DetailContract;
import com.bana.fvs.app.mvp.model.DetailModel;
import com.wei.commonlibrary.net.CommException;
import com.wei.commonlibrary.net.MyDefaultCallback;

import java.util.ArrayList;
import java.util.HashMap;

/**
 * Author : yanftch
 * Date : 2018/3/2
 * Time : 22:29
 * Desc :
 */

public class DetailPresenter extends DetailContract.AbsDetailPresnter {

    @Override
    public void http_fogAreaEquipment(Activity activity, String token, String wqbm) {
        mModel.http_fogAreaEquipment(token, wqbm).callback(new MyDefaultCallback<FogAreaInfoBean>(activity, true) {
            @Override
            public void onError(CommException e) {
                if (null != getView()) {
                    getView().onError(e);
                }
            }

            @Override
            public void response(FogAreaInfoBean bean) {
                if (null != getView()) {
                    getView().fogAreaInfo(bean);
                }
            }
        });
    }

    @Override
    public void http_foglightEquipment(Activity activity, String token, String sbbm,String kzpbm) {
        mModel.http_foglightEquipment(token, sbbm,kzpbm).callback(new MyDefaultCallback<FoglightDetailInfo>(activity, true) {
            @Override
            public void onError(CommException e) {
                if (null != getView()) {
                    getView().onError(e);
                }
            }

            @Override
            public void response(FoglightDetailInfo foglightDetailInfo) {
                if (null != getView()) {
                    getView().foglightInfo(foglightDetailInfo);
                }
            }
        });
    }

    /**
     * 区域控制器
     */
    @Override
    public void http_controllerEquipment(Activity activity, String token, String sbbm) {
        mModel.http_controllerEquipment(token, sbbm).callback(new MyDefaultCallback<AreaControllerDetailBean>(activity, true) {
            @Override
            public void onError(CommException e) {
                if (null != getView()) {
                    getView().onError(e);
                }
            }

            @Override
            public void response(AreaControllerDetailBean bean) {
                if (null != getView()) {
                    getView().onResponse(bean);
                }
            }
        });
    }

    /**
     * 能见度检测仪详情
     */
    @Override
    public void http_visibilityDetectionEquipment(Activity activity, String token, String sbbm) {
        mModel.http_visibilityDetectionquipment(token, sbbm).callback(new MyDefaultCallback<VisibilityControllerDetailBean>(activity, true) {
            @Override
            public void onError(CommException e) {
                if (null != getView()) {
                    getView().onError(e);
                }
            }

            @Override
            public void response(VisibilityControllerDetailBean bean) {
                if (null != getView()) {
                    getView().visibilityDetectInfo(bean);
                }
            }
        });
    }

    @Override
    public void http_updateFogAreaTimer(Activity activity, String token, String wqbh, boolean sfds) {
        mModel.http_updateFogAreaTimer(token, wqbh,sfds).callback(new MyDefaultCallback<CommonEntity>(activity, true) {
            @Override
            public void onError(CommException e) {
                if (null != getView()) {
                    getView().onError(e);
                }
            }

            @Override
            public void response(CommonEntity bean) {
                if (null != getView()) {
                    getView().updateFogAreaTimerInfo(bean);
                }
            }
        });
    }

    @Override
    public void http_foglightWorkModeUpdate(Activity activity, String token, HashMap<String,Object> data) {
        mModel.http_foglightWorkModeUpdate(token, data).callback(new MyDefaultCallback<ArrayList<UpdateWorkModeResultBean.Item2Bean>>(activity, true) {
            @Override
            public void onError(CommException e) {
                if (null != getView()) {
                    getView().onError(e);
                }
            }

            @Override
            public void response(ArrayList<UpdateWorkModeResultBean.Item2Bean> bean) {
                if (null != getView()) {
                    getView().updtaeFogLightMode(bean);
                }
            }
        });
    }

    @Override
    protected DetailContract.AbsDetailModel createModel() {
        return new DetailModel();
    }
}
